import random

import requests
import logging
import config
class MonitorAPI:

    #添加监测类型
    @classmethod
    def add_equipment_tpye(cls,token,body):
        url = config.monitor_domain + "/monitor/equipmentType/saveMet"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid, "content-type": "application/json"}
        resp = requests.post(url=url, headers=headers, json=body)
        logging.info(f"add_equipment_tpye url:{url}")
        logging.info(f"add_equipment_tpye resp: {resp.text}")
        return resp

    # 获取监控设备参数类型
    @classmethod
    def query_monitor_list(cls, token, paramName):
        url = config.monitor_domain + f"/monitor/equipmentType/selectPageList?equipmentTypeName={paramName}&pageNum=1&pageSize=100"
        uuid = "a9f25c87-" + str(random.randint(1000, 9999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"query_monitor_list url:{url}")
        logging.info(f"query_monitor_list resp: {resp.text}")
        return resp

    # 删除监控类型参数
    @classmethod
    def delete_monitor_type(cls, token, id):
        url = config.monitor_domain + f"/monitor/equipmentType/deleteTypes/{id}"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.delete(url=url, headers=headers)
        logging.info(f"delete_monitor_type url:{url}")
        logging.info(f"delete_monitor_type resp: {resp.text}")
        return resp

    #给监测设备类型关联参数
    @classmethod
    def setDevice_typeMonitorLink(cls,token,body):
        url = config.monitor_domain + "/monitor/param/setDeviceTypeMonitorLink"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid, "content-type": "application/json"}
        resp = requests.post(url=url, headers=headers, json=body)
        logging.info(f"setDevice_typeMonitorLink url:{url}")
        logging.info(f"setDevice_typeMonitorLink resp: {resp.text}")
        return resp
        pass
    #查询监测设备类型关联参数
    @classmethod
    def query_monitor_link_paramter(cls,token,deviceTypeCode):
        url = config.monitor_domain + f"/monitor/param/selectMonitorParamByDeviceTypeCode?deviceTypeCode={deviceTypeCode}&pageNum=1&pageSize=10"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"query_monitor_link_paramter url:{url}")
        logging.info(f"query_monitor_link_paramter resp: {resp.text}")
        return resp

    #删除监测设备类型关联参数
    @classmethod
    def delete_monitor_link_paramter(cls,token,id):
        url = config.monitor_domain + f"/monitor/param/deleteDeviceTypeMonitorLink/{id}"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.delete(url=url, headers=headers)
        logging.info(f"delete_monitor_link_paramter url:{url}")
        logging.info(f"delete_monitor_link_paramter resp: {resp.text}")
        return resp

    #给一所一档关联关联 监测系统管理
    @classmethod
    def add_cmDeviceMonitoringSystem(cls,token,body):
        url = config.monitor_domain + "/cmDeviceMonitoringSystem/add"
        uuid = "a9f25c87-" + str(random.randint(1000, 99999))
        headers = {"Authorization": token, "Uuidstr": uuid, "content-type": "application/json"}
        resp = requests.post(url=url, headers=headers, json=body)
        logging.info(f"add_cmDeviceMonitoringSystem url:{url}")
        logging.info(f"add_cmDeviceMonitoringSystem resp: {resp.text}")
        return resp
        pass

    # 给一所一档查看 监测系统管理
    @classmethod
    def query_cmDeviceMonitoringSystem(cls,token,id):
        url = config.monitor_domain + f"/cmDeviceMonitoringSystem/list/{id}"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid, "content-type": "application/json"}
        resp = requests.post(url=url, headers=headers)
        logging.info(f"query_cmDeviceMonitoringSystem url:{url}")
        logging.info(f"query_cmDeviceMonitoringSystem resp: {resp.text}")
        return resp

    # 给一所一档删除 监测系统管理
    @classmethod
    def delete_cmDeviceMonitoringSystem(cls, token, id):
        url = config.monitor_domain + f"/cmDeviceMonitoringSystem/remove/{id}"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid,}
        resp = requests.delete(url=url, headers=headers)
        logging.info(f"delete_cmDeviceMonitoringSystem url:{url}")
        logging.info(f"delete_cmDeviceMonitoringSystem resp: {resp.text}")
        return resp

    # 给一所一档：添加监测设备
    @classmethod
    def add_cmDevice(cls, token, body):
        url = config.monitor_domain + "/cms/otherDevice/addDevice"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid, "content-type": "application/json"}
        resp = requests.post(url=url, headers=headers, json=body)
        logging.info(f"add_cmDevice url:{url}")
        logging.info(f"add_cmDevice resp: {resp.text}")
        return resp
        pass

    #给一所一档：查看监测设备
    @classmethod
    def query_cmDevice(cls,token,deviceName,stationId='',deviceBigType=''):
        url = config.monitor_domain + f"/cms/otherDevice/deviceList?pageNum=1&pageSize=100&deviceName={deviceName}&stationId={stationId}&deviceBigType={deviceBigType}"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid}
        resp = requests.get(url=url, headers=headers)
        logging.info(f"query_cmDevice url:{url}")
        logging.info(f"query_cmDevice resp: {resp.text}")
        return resp

    # 给一所一档 删除 监测设备 id来删除
    @classmethod
    def delete_cmDevice(cls, token,data):
        url = config.monitor_domain + "/cms/otherDevice/deleteDevice"
        uuid = "a9f25c87-" + str(random.randint(1000, 999999))
        headers = {"Authorization": token, "Uuidstr": uuid,"content-type": "application/json" }
        resp = requests.post(url=url, headers=headers,json=data)
        logging.info(f"delete_cmDevice url:{url}")
        logging.info(f"delete_cmDevice resp: {resp.text}")
        return resp


